package net.hzlj.platform.enterprise.receiver;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.NotificationCompat;
import android.util.Log;

import net.hzlj.platform.enterprise.BootApp;
import net.hzlj.platform.enterprise.activity.HomeActivity;
import net.hzlj.rl.zhangjiajie.R;

/**
 * @ClassName:LocationNotification
 * @Description:定位通知
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2015年11月25日09:17:45
 */
public class LocationNotification {

    /**
     * 通知栏Id
     */
    int LOCATION_NOTIFI_ID = 900001;

    String LOCATION_NOTIFI_TAG = "LOCATION_NOTIFI_TAG";

    protected static LocationNotification mLocationNotification;

    private static final String TAG = LocationNotification.class.getSimpleName();

    /**
     * 通知栏跳转
     */
    private PendingIntent mPendingIntent;

    /**
     * 通知栏提示
     */
    private Notification mNotification;

    /**
     * 通知栏管理类
     */
    private NotificationManager mNotificationManager;

    /**
     * 构造方法
     * [构造简要说明]
     */
    private LocationNotification() {
        mNotificationManager =
                (NotificationManager) BootApp.mAppContext
                        .getSystemService(Context.NOTIFICATION_SERVICE);
    }

    public Notification getNotification() {
        if (null != mNotification) {
            return mNotification;
        }
        return null;
    }

    /**
     * 获取单一实例.
     * [一句话功能简述]<BR>
     * [功能详细描述]
     *
     * @return UMusicDownldNotifiLogic 返回当前类的实例
     */
    public static synchronized LocationNotification getInstance() {
        if (mLocationNotification == null) {
            mLocationNotification = new LocationNotification();
        }
        return mLocationNotification;
    }

    /**
     * 关闭通知栏
     */
    public void cancelDownldNotification() {
        Log.d(TAG, "cancelDownldNotifi()");
        if (mNotification != null) {
            mNotificationManager.cancel(LOCATION_NOTIFI_TAG, LOCATION_NOTIFI_ID);
            mNotification = null;
        }
    }

    /**
     * 创建通知栏
     */
    public void createNotification(Context context) {
        Log.d(TAG, "createNotification()");
        Intent intent = new Intent(context, HomeActivity.class);
        intent.putExtra("fromNotification", true);
        mPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setContentTitle(context.getString(R.string.app_title));
        builder.setContentText(context.getString(R.string.locate_starting));
        builder.setContentIntent(mPendingIntent);
        mNotification = builder.build();
    }
}
